// pages/companylist/companylist.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    officeId: '',
    staffArray: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      officeId: options.officeId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.queryData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 添加员工信息
   */
  addStaff: function () {
    var that = this
    wx.navigateTo({
      url: '/pages/addstaff/addstaff?officeId=' + that.data.officeId,
    })
  },

  /**
  * 查询数据
  */
  queryData: function () {
    wx.showLoading({
      title: '正在查询...',
    })
    var that = this;
    var model = {};
    model.openid = getApp().globalData.openId;
    model.officeid = that.data.officeId;
    wx.request({
      url: getApp().BASE_URL + '/wxoffice/getOfficePeopleList ',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      method: 'POST',
      data: model,
      success: function (res) {
        console.log(res)
        if (res.data.code == 200) {
          wx.hideLoading();
          that.data.staffArray = [];
          that.setData({
            staffArray: res.data.data
          })
          console.log(that.data.staffArray)
        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      },
      fail: function (res) {
        wx.hideLoading();
        that.showErroMessage(res.data.msg)
      },
      complete: function (res) {

      }
    })

  },

  /**
   * 显示信息
   */
  showErroMessage: function (mes) {
    wx.showToast({
      title: mes,
      icon: 'none',
      duration: 1500
    })
  },

  /**
   * item点击事件
   */
  itemClick(e) {
    var that = this
    var index = e.currentTarget.dataset.index;
    console.log(index)
    var id = that.data.staffArray[index].id
    wx.navigateTo({
      url: '/pages/companyuserdetail/companyuserdetail?id=' + id,
    })

  }

})